package com.smartleanx.module.hrm.service.examine.examineAssessmentScope;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.smartleanx.module.hrm.controller.admin.examine.examineAssessmentScope.vo.*;
import com.smartleanx.module.hrm.dal.dataobject.examine.examineAssessmentScope.ExamineAssessmentScopeDO;
import com.smartleanx.framework.common.pojo.PageResult;
import com.smartleanx.framework.common.pojo.PageParam;
import com.smartleanx.framework.common.util.object.BeanUtils;

import com.smartleanx.module.hrm.dal.mysql.examine.examineAssessmentScope.ExamineAssessmentScopeMapper;

import static com.smartleanx.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.smartleanx.module.hrm.enums.ErrorCodeConstants.*;

/**
 * 考核范围 Service 实现类
 *
 * @author 
 */
@Service
@Validated
public class ExamineAssessmentScopeServiceImpl implements ExamineAssessmentScopeService {

    @Resource
    private ExamineAssessmentScopeMapper examineAssessmentScopeMapper;

    @Override
    public Integer createExamineAssessmentScope(ExamineAssessmentScopeSaveReqVO createReqVO) {
        // 插入
        ExamineAssessmentScopeDO examineAssessmentScope = BeanUtils.toBean(createReqVO, ExamineAssessmentScopeDO.class);
        examineAssessmentScopeMapper.insert(examineAssessmentScope);
        // 返回
        return examineAssessmentScope.getId();
    }

    @Override
    public void updateExamineAssessmentScope(ExamineAssessmentScopeSaveReqVO updateReqVO) {
        // 校验存在
        validateExamineAssessmentScopeExists(updateReqVO.getId());
        // 更新
        ExamineAssessmentScopeDO updateObj = BeanUtils.toBean(updateReqVO, ExamineAssessmentScopeDO.class);
        examineAssessmentScopeMapper.updateById(updateObj);
    }

    @Override
    public void deleteExamineAssessmentScope(Integer id) {
        // 校验存在
        validateExamineAssessmentScopeExists(id);
        // 删除
        examineAssessmentScopeMapper.deleteById(id);
    }

    private void validateExamineAssessmentScopeExists(Integer id) {
        if (examineAssessmentScopeMapper.selectById(id) == null) {
            throw exception(EXAMINE_ASSESSMENT_SCOPE_NOT_EXISTS);
        }
    }

    @Override
    public ExamineAssessmentScopeDO getExamineAssessmentScope(Integer id) {
        return examineAssessmentScopeMapper.selectById(id);
    }

    @Override
    public PageResult<ExamineAssessmentScopeDO> getExamineAssessmentScopePage(ExamineAssessmentScopePageReqVO pageReqVO) {
        return examineAssessmentScopeMapper.selectPage(pageReqVO);
    }

}